package com.zwps.biz.controller.http;

import com.zwps.biz.api.model.dto.log.api.SelectLogApiDTO;
import com.zwps.biz.api.model.dto.log.message.BatchDeleteDTO;
import com.zwps.biz.api.model.vo.log.api.SelectLogApiVO;
import com.zwps.biz.domain.service.LogApiService;
import com.zwps.common.api.model.vo.NameCodeOptionVO;
import com.zwps.common.controller.response.message.ResponseDataPageMessage;
import com.zwps.common.core.enums.LogTypeEnum;
import com.zwps.common.core.enums.OperateTypeEnum;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

@Tag(name = "接口日志")
@RestController
@Validated
@RequestMapping("system/log/api")
public class LogApiController {

    @Autowired
    private LogApiService logApiService;

    @Operation(summary = "删除接口日志")
    @DeleteMapping
    public void deletelogApi(@Valid @NotNull @RequestBody BatchDeleteDTO dto) {
        logApiService.deleteLogApi(dto.getIds());
    }

    @Operation(summary = "分页查询接口日志")
    @GetMapping("page")
    public ResponseDataPageMessage<SelectLogApiVO> selectlogApiPage(SelectLogApiDTO dto) {
        return ResponseDataPageMessage.data(logApiService.selectLogApiPage(dto));
    }

    @Operation(summary = "日志类型选项")
    @GetMapping("log_type_option")
    public List<NameCodeOptionVO> selectLogTypeOption() {
        List<NameCodeOptionVO> list = new ArrayList<NameCodeOptionVO>();
        for (LogTypeEnum type : LogTypeEnum.values()) {
            list.add(NameCodeOptionVO.builder().code(type.getCode()).name(type.getName()).build());
        }
        return list;
    }

    @Operation(summary = "日志操作类型选项")
    @GetMapping("operate_type_option")
    public List<NameCodeOptionVO> selectOperateTypeOption() {
        List<NameCodeOptionVO> list = new ArrayList<NameCodeOptionVO>();
        for (OperateTypeEnum type : OperateTypeEnum.values()) {
            list.add(NameCodeOptionVO.builder().code(type.getCode()).name(type.getName()).build());
        }
        return list;
    }
}
